-- get_cream
-- Created by wangy Mar/29/2016
-- 分解宝物时时，可获得淬火精华

local CREAM_ITEM_ID = 7303;  -- 淬火精华的物品编号

return {
    apply = function(prop, baseValue)
        return tonumber(prop[3]);
    end,

    -- 击杀触发
    trigger = function(who, prop, args)
        local classId = args.classId;
        local count   = args.count;

        -- 计算可增加的进度
        local rank = EquipM.query(classId, "rank");
        local addValue = rank * count;

        -- 获取装备锻造进度
        local curProgress = DungeonM.getDungeonMixedField("equip_forge_progress") or 0;
        local maxProgress = prop[3];

        -- 计算可获得的淬火精华数量
        local amount = math.modf((curProgress + addValue) / maxProgress);
        if amount > 0 then
            local bonus = { 1, CREAM_ITEM_ID, amount, };
            BonusM.doBonus(bonus, "get_cream");

            local itemName = ItemM.query(CREAM_ITEM_ID, "name");
            local msg = string.format(getLocStr("equip_forge_tip"), itemName, amount);
            doAlert(msg);
        end

        -- 更新进度
        local remainProgress = (curProgress + addValue) % maxProgress;
        DungeonM.setDungeonMixedField("equip_forge_progress", remainProgress);

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local propDesc = row.desc;
        local curProgress = DungeonM.getDungeonMixedField("equip_forge_progress") or 0;
        local maxProgress = prop[3];
        propDesc = string.gsub(propDesc, "{0}", curProgress);
        propDesc = string.gsub(propDesc, "{1}", maxProgress);
        return propDesc;
    end,
};